home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
127_01
/
rap1.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
17KB
|
598 lines
/*********************************************************************\
** .---------------------------------------------------------------. **
** | | **
** | | **
** | Copyright (c) 1981, 1982, 1983 by Eric Martz. | **
** | | **
** | | **
** | Permission is hereby granted to use this source | **
** | code only for non-profit purposes. Publication of | **
** | all or any part of this source code, as well as | **
** | use for business purposes is forbidden without | **
** | written permission of the author and copyright | **
** | holder: | **
** | | **
** | Eric Martz | **
** | POWER TOOLS | **
** | 48 Hunter's Hill Circle | **
** | Amherst MA 01002 USA | **
** | | **
** | | **
** `---------------------------------------------------------------' **
\*********************************************************************/
#include "rap.h"
/*****************************************************************
this function decodes the command type, returning the type, or
UNKNOWN.
*******************************************************************/
int comtyp (line)
char *line;
{
char let1, let2;
let1 = toupper( line[1] );
let2 = toupper( line[2] );
if ( let1 EQ 'A' && let2 EQ 'R') return( AR );
if ( let1 EQ 'B' && let2 EQ 'D') return( BD );
if ( let1 EQ 'B' && let2 EQ 'L') return( BL );
if ( let1 EQ 'B' && let2 EQ 'O') return( BO );
if ( let1 EQ 'B' && let2 EQ 'P') return( BP );
if ( let1 EQ 'B' && let2 EQ 'R') return( BR );
if ( let1 EQ 'C' && let2 EQ 'C') return( CC );
if ( let1 EQ 'C' && let2 EQ 'E') return( CE );
if ( let1 EQ 'C' && let2 EQ 'F') return( CF );
if ( let1 EQ 'D' && let2 EQ '1') return( D1 );
if ( let1 EQ 'D' && let2 EQ '2') return( D2 );
#ifdef DEBUG
if ( let1 EQ 'D' && let2 EQ 'E') return( DEBUG );
#endif
if ( let1 EQ 'E' && let2 EQ 'C') return( EC );
if ( let1 EQ 'E' && let2 EQ 'D') return( ED );
if ( let1 EQ 'F' && let2 EQ 'I') return( FI );
if ( let1 EQ 'F' && let2 EQ 'O') return( FO );
if ( let1 EQ 'F' && let2 EQ 'N') return( FN );
if ( let1 EQ 'H' && let2 EQ 'E') return( HE );
if ( let1 EQ 'I' && let2 EQ '@') return( IAT);
if ( let1 EQ 'I' && let2 EQ 'C') return( IC );
if ( let1 EQ 'I' && let2 EQ 'G') return( IG );
if ( let1 EQ 'I' && let2 EQ 'N') return( IN );
if ( let1 EQ 'I' && let2 EQ 'X') return( IX );
if ( let1 EQ 'J' && let2 EQ 'U') return( JU );
if ( let1 EQ 'L' && let2 EQ 'F') return( LF );
if ( let1 EQ 'L' && let2 EQ 'S') return( LS );
if ( let1 EQ 'M') {
if (let2 EQ '1') return( M1 );
if (let2 EQ '2') return( M2 );
if (let2 EQ '3') return( M3 );
if (let2 EQ '4') return( M4 );
if (let2 EQ 'O') return( MO );
}
if ( let1 EQ 'N' && let2 EQ 'E') return( NEED );
if ( let1 EQ 'N' && let2 EQ 'F') return( NF );
if ( let1 EQ 'N' && let2 EQ 'J') return( NJ );
if ( let1 EQ 'N' && let2 EQ 'X') return( NX );
if ( let1 EQ 'O' && let2 EQ 'U') return( OU );
if ( let1 EQ 'P' && let2 EQ '#') return( PNO );
if ( let1 EQ 'P' && let2 EQ 'D') return( PD );
if ( let1 EQ 'P' && let2 EQ 'I') return( PI );
if ( let1 EQ 'P' && let2 EQ 'L') return( PL );
if ( let1 EQ 'R' && let2 EQ 'E') return( RE );
if ( let1 EQ 'R' && let2 EQ 'M') return( RM );
if ( let1 EQ 'R' && let2 EQ 'F') return( RF );
if ( let1 EQ 'S' && let2 EQ 'A') return( SA );
if ( let1 EQ 'S' && let2 EQ 'P') return( SP );
if ( let1 EQ 'S' && let2 EQ 'S') return( SS );
if ( let1 EQ 'T' && let2 EQ 'A') return( TA );
if ( let1 EQ 'T' && let2 EQ 'C') return( TC );
if ( let1 EQ 'T' && let2 EQ 'I') return( TI );
if ( let1 EQ 'U' && let2 EQ 'L') return( UL );
if ( let1 EQ Pre_ss_delim &&
let2 EQ Pre_ss_delim) return( PRE_SS );
if ( let1 EQ Post_ss_delim &&
let2 EQ Post_ss_delim) return( POST_SS );
return( UNKNOWN ); /* no match */
}
/*********************************************************************
Skips white-space characters at the beginning of a string.
*********************************************************************/
skip_blanks ( string )
char *string;
{
char local[ MAXLINE ];
int i, j, k;
strcpy ( local, string );
for (i = 0;
(local[i] EQ ' ' || local[i] EQ '\t' || local[i] EQ '\n');
i++);
for (j = 0; (string[j] = local[i]) NE '\0' ; i++, j++ ) ;
return;
}
/*********************************************************************
Truncates white-space characters at the end of a string.
*********************************************************************/
trunc_bl (string)
char *string;
{
char *ptr;
int k;
k = strlen (string);
ptr = &string[ k-1 ]; /* char before terminating nul */
while (*ptr EQ BLANK || *ptr EQ TAB || *ptr EQ NEWLINE)
*ptr-- = '\0';
}
/*******************************************************************
performs the formatting command returned by comtyp - sets global
variables ( indenting, underlining, etc. )
*******************************************************************/
command (line, nx, valid)
char *line, *nx;
int *valid;
{
int c_type; /* command type */
int arg_val; /* argument value, if any */
char arg_sign; /* relative (+ or -) or absolute */
int i;
c_type = comtyp (line);
#ifdef DEBUG
if (Debug) fprintf(STDERR,"COMMAND %d\n",c_type);
#endif
if (c_type EQ UNKNOWN) /* IGNORE ALIEN ORDERS */
{
fprintf(STDERR,
"UNKNOWN COMMAND at line %d: <%s>\n",In_linecnt,line);
*valid = NO;
return(0);
}
*valid = YES;
arg_val = get_val ( line, &arg_sign );
#ifdef DEBUG
if (Debug) fprintf(STDERR,
"get_val returned arg_val = %d, arg_sign = %c \n",
arg_val, arg_sign);
#endif
switch (c_type) {
case AR : /* assign value to arabic {#{ */
set(&Arabic, arg_val, arg_sign, 1, 0, 32000);
break;
case TC: /* table of contents */
if (Tabcont) extract(line+4);
break;
case IX: /* index */
if (Index) extract(line+4);
break;
case PD: /* print draft */
set(&Printdraft, arg_val, arg_sign, 1, 0, 1);
break;
case BD: /* begin draft */
Indraft = YES;
break;
case ED: /* end draft */
Indraft = NO;
break;
case FI : /* filled lines */
brk(CR); /* flush out last unfilled */
Fill = YES;
Tival = Pival;
break;
case NEED: /* need arg_val lines */
if ((arg_val + Lineno - 1) > Bottom) space(HUGE);
break;
case NF : /* non-filled lines */
brk(CR); /* flush out */
Fill = NO;
Tival = Inval;
break; /* down and cry */
case BR : /* just cause a break */
brk(CR);
Tival = Pival;
break;
case LS : /* set line spacing value */
set (&Lsval, arg_val, arg_sign, 1, 1, HUGE );
break;
case TI : /* set temporary left indent */
brk(CR);
set ( &Tival, arg_val, arg_sign, 5, 0, Rmval );
break;
case PI : /* set paragraph indent */
set (&Pival, arg_val, arg_sign, Inval+5, -HUGE, HUGE);
brk(CR);
if (Fill) Tival = Pival;
break;
case IN : /* set left indent */
brk(CR);
set ( &Inval, arg_val, arg_sign, 0, 0, Rmval-1 );
Pival = Inval;
if (Fill) Tival = Pival;
else Tival = Inval;
break;
case RM: /* set right margin */
set ( &Rmval, arg_val, arg_sign, 78, Tival+1, HUGE );
break;
case RF: /* restore font to primary/default */
if ( /*Sanders AND*/ Font_o)